<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    var aa = 6
    var bb = 18
    var arr= []
     for (var i = 6; i >0; i--) {
       for (var j = 18; j>0; j--) {
            if(aa%i==0 && bb%j==0 ){
                if(i==j){

                arr.push(i)
                
                }
                

            }
            
        }
    }
    console.log(arr)
    var max = Math.max.apply(null, arr);
    console.log(max)

</script>V